﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BinarTtree.MaxDepth
{
    public class TreeNode
    {
        public int val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(int val = 0, TreeNode left = null, TreeNode right = null)
        {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    class MainProject
    {
        static void Main(string[] args)
        {
            //TreeNode treeNode = new TreeNode(1, new TreeNode(2, new TreeNode(4), new TreeNode(5)), new TreeNode(3, new TreeNode(6), new TreeNode(7)));
            TreeNode treeNode = new TreeNode(1, null, new TreeNode(2, new TreeNode(3)));
            Console.WriteLine(MaxDepth(treeNode));
            //LevelOrder(treeNode);
            Console.ReadKey();
        }
        public static int MaxDepth(TreeNode root)
        {
            //后续遍历
            //return root == null ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
            return root == null ? 0 : Math.Max(MaxDepth(root.left), MaxDepth(root.right)) + 1;

        }

        //public static int Max(TreeNode root)
        //{
        //    //return root == null ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;


        //}
    }
}
